package com.nl.controller.web.service;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.util.Base64Utils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nl.controller.common.annotation.SystemServiceLog;
import com.nl.controller.common.exception.SmsException;
import com.nl.controller.common.model.BaseResult;
import com.nl.controller.common.service.CommonService;
import com.nl.controller.web.bean.BdResult;
import com.nl.controller.web.bean.SmsAllStation;
import com.nl.controller.web.bean.SmsBaseStation;
import com.nl.controller.web.bean.SmsMgrTemplateInfo;
import com.nl.controller.web.bean.XuYiStation;
import com.nl.controller.web.bean.sendLimit.QxjSendScope;
import com.nl.controller.web.mapper.SmsAreaMapper;
import com.nl.controller.web.util.DoubleUtil;
import com.nl.controller.web.util.HttpClientUtil;

import lombok.extern.slf4j.Slf4j;
@Service
@Slf4j
public class SmsAreaService {
	@Autowired
	private CommonService commonService;
	@Autowired
	private SmsAreaMapper smsAreaMapper;
	@Resource
	@Autowired
	private ExecutorService executorService;
	@SystemServiceLog(description = "插入基站信息异常", value = false)
	public int ins(Integer flag1,String mgrId,ConcurrentLinkedQueue<SmsBaseStation> SmsBaseStationList) throws Exception{
		final int flag=1;
		executorService.execute(new Runnable() {
			@Override
			public void run() {
				log.info("插入基站线程启动");
				int count =0;
				try {
					List<SmsBaseStation> smsBaseStations = new ArrayList<SmsBaseStation>() ;
					log.info("基站总量"+SmsBaseStationList.size());
					while (true) {
						count++;
						SmsBaseStation SmsBaseStation =SmsBaseStationList.poll();
						if (null ==SmsBaseStation ) {
							 smsAreaMapper.insertSmsBaseStation(smsBaseStations);
							smsBaseStations.clear();
							break;
						}
						smsBaseStations.add(SmsBaseStation);
						if (count !=0 && count % 2000 == 0) {
							 smsAreaMapper.insertSmsBaseStation(smsBaseStations);
							smsBaseStations.clear();
						}
					}
				} catch (Exception e) {
					e.printStackTrace();
					throw new SmsException("插入基站信息异常");
				}
			}
		});
		return flag;
	}

	@SystemServiceLog(description = "初始化发送区域编码", value = false)
	public String getRegionId() {
		String regionId = "";
		try {
			regionId = smsAreaMapper.getRegionId();
		} catch (Exception e) {
			e.printStackTrace();
			log.error("初始化发送区域编码");
			throw new SmsException("初始化发送区域编码异常");
		}
		return regionId;
	}
	@SystemServiceLog(description = "插入基站信息异常", value = false)
	public int insertSmsBaseStation(String mgrId,ConcurrentLinkedQueue<SmsBaseStation> SmsBaseStationList) {
		int flag=-1;
		int count =0;
		try {
			List<SmsBaseStation> smsBaseStations = new ArrayList<SmsBaseStation>() ;
			log.info("基站总量"+SmsBaseStationList.size());
			while (true) {
				count++;
				SmsBaseStation SmsBaseStation =SmsBaseStationList.poll();
				if (null ==SmsBaseStation ) {
					flag=smsAreaMapper.insertSmsBaseStation(smsBaseStations);
					smsBaseStations.clear();
					break;
				}
				smsBaseStations.add(SmsBaseStation);
				if (count !=0 && count % 2000 == 0) {
					flag=smsAreaMapper.insertSmsBaseStation(smsBaseStations);
					smsBaseStations.clear();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			throw new SmsException("插入基站信息异常");
		}
		return flag;
	}

	@SystemServiceLog(description = "查询全省所有基站信息地图", value = false)
	public List<SmsAllStation> findAllStation(String cityId, String countyId,String longitudeMin,String longitudeMax,String latitudeMin,String latitudeMax) {
		Map<String, Object> map = new HashMap<>();
		/*map.put("cityId", cityId);
        String[] arr = null ;
        if (countyId.length() > 0) {
            if (",".equals(String.valueOf(countyId.charAt(countyId.length() - 1)))) {
                countyId = countyId.substring(0, countyId.length() - 1);
                arr=countyId.split(",");
            }else{
                arr=countyId.split(",");
            }
        }
        map.put("countyIds", arr);*/
		map.put("longitudeMin", longitudeMin);
		map.put("longitudeMax", longitudeMax);
		map.put("latitudeMin", latitudeMin);
		map.put("latitudeMax", latitudeMax);
		List<SmsAllStation> list = new ArrayList<>();
		try {
			list = smsAreaMapper.findAllStation(map);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("查询全省基站信息表");
			throw new SmsException("查询全省基站信息表出现异常");
		}
		return list;
	}

	public List<Object>  mapSave (String cityId, String mgrId,String resultRegionType,String resultRegionValue,String msisdn,String regionId){
		smsAreaMapper.updateMgrTemplateInfo(mgrId, resultRegionType, resultRegionValue, msisdn,cityId,regionId);
		smsAreaMapper.delSmsBaseStation(mgrId);
		int saveFlag  = smsAreaMapper.addStation(mgrId);
		List<Object> result = new ArrayList<>();
		result.add(saveFlag);
		result.add("0");
		result.add(regionId);
		result.add(resultRegionType);
		result.add(resultRegionValue);
		return result;
	}

	@Transactional
	@SystemServiceLog(description = "根据地图区域更新基站表", value = false)
	public List<Object> mapSave(String cityId, String mgrId,String resultRegionType,String resultRegionValue,JSONArray jsonArray,String msisdn) throws IOException {
		int stationNum=0;//基站数量
		int saveFlag=-1;
		String resultRegionId="";
		try {
			resultRegionId=smsAreaMapper.qryRegionId(mgrId);
			if("区域编码".equals(resultRegionId)||"".equals(resultRegionId)||null==resultRegionId){
				resultRegionId= this.getRegionId();
			}
			int result = smsAreaMapper.updateMgrTemplateInfo(mgrId, resultRegionType, resultRegionValue, msisdn,cityId,resultRegionId);
			if (1 == result) {
				int isExistMgrId=smsAreaMapper.checkBaseStationByid(mgrId);//基站信息表是否存在该项目
				if(isExistMgrId>0){//存在就更新
					int delFlag=-1;
					/*resultRegionId=smsAreaMapper.qryRegionId(mgrId);*/
					delFlag=smsAreaMapper.delSmsBaseStation(mgrId);
					List<ConcurrentLinkedQueue<SmsBaseStation>> list = new ArrayList<ConcurrentLinkedQueue<SmsBaseStation>>();
					int count =0;
					ConcurrentLinkedQueue<SmsBaseStation> SmsBaseStationList = new ConcurrentLinkedQueue<SmsBaseStation>();
					stationNum=jsonArray.size();
					System.out.println("stationNum==map==================="+stationNum);
					if(jsonArray.size()>0&&resultRegionId!=""){
						for (int i = 0; i < jsonArray.size(); i++) {
							count++;
							if (i == jsonArray.size() -1) {
								list.add(SmsBaseStationList);
							}
							if (count%5000==0) {
								list.add(SmsBaseStationList);
								SmsBaseStationList = new ConcurrentLinkedQueue<SmsBaseStation>();
							}
							SmsBaseStation baseStation = new SmsBaseStation();
							baseStation.setCityId(cityId);
							baseStation.setId(mgrId);
							baseStation.setRegionId(resultRegionId);
							baseStation.setStationId(jsonArray.getJSONObject(i).getString("stationid"));
							baseStation.setStationName(jsonArray.getJSONObject(i).getString("stationname"));
							SmsBaseStationList.add(baseStation);
						}
					}
					if(delFlag>0){//删除成功再插入
						for (ConcurrentLinkedQueue<SmsBaseStation> baseStation : list) {
//							InsertStation insertStation = new InsertStation(mgrId,baseStation);
//							saveFlag = Integer.parseInt((String) insertStation.fal.get());
							saveFlag = this.ins(saveFlag,mgrId, baseStation);
						}
					}
				}else{//不存在就添加
					resultRegionId= this.getRegionId();
					List<ConcurrentLinkedQueue<SmsBaseStation>> list = new ArrayList<ConcurrentLinkedQueue<SmsBaseStation>>();
					ConcurrentLinkedQueue<SmsBaseStation> SmsBaseStationList = new ConcurrentLinkedQueue<SmsBaseStation>();
					stationNum=jsonArray.size();
					int count =0;
					if(jsonArray.size()>0){
						for (int i = 0; i < jsonArray.size(); i++) {
							count++;
							if (i == jsonArray.size() -1) {
								list.add(SmsBaseStationList);
							}
							if (count%5000==0) {
								list.add(SmsBaseStationList);
								SmsBaseStationList = new ConcurrentLinkedQueue<SmsBaseStation>();
							}
							SmsBaseStation baseStation = new SmsBaseStation();
							baseStation.setCityId(cityId);
							baseStation.setId(mgrId);
							baseStation.setRegionId(resultRegionId);
							baseStation.setStationId(jsonArray.getJSONObject(i).getString("stationid"));
							baseStation.setStationName(jsonArray.getJSONObject(i).getString("stationname"));
							SmsBaseStationList.add(baseStation);
						}
					}
					for (ConcurrentLinkedQueue<SmsBaseStation> baseStation : list) {
//						InsertStation insertStation = new InsertStation(mgrId,baseStation);
//						saveFlag = Integer.parseInt((String) insertStation.fal.get());
						saveFlag = this.ins(saveFlag,mgrId, baseStation);
					}
				}
			}
		} catch (Exception e) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			e.printStackTrace();
			saveFlag =-1;
			throw new SmsException("基站信息表与模板表");
		}
		List<Object> result = new ArrayList<Object>();
		result.add(saveFlag);
		result.add(stationNum);
		result.add(resultRegionId);
		result.add(resultRegionType);
		result.add(resultRegionValue);
		return result;
	}

	@SystemServiceLog(description = "根据区县更新基站表", value = false)
	public List<Object> countySave(String cityId, String mgrId,String countyId,String stationIds) throws IOException {
		List<Object> result = new ArrayList<Object>();
		int stationNum=0;//基站数量
		int saveFlag=-1;
		String resultRegionId="";
		List<SmsAllStation> list= this.findAllStationIdsByCounty(stationIds);
		//List<SmsAllStation> list= this.findAllStationByCounty(cityId, countyId);

		int isExistMgrId=smsAreaMapper.checkBaseStationByid(mgrId);//基站信息表是否存在该项目
		if(list.size()>0){
			if(isExistMgrId>0){//存在就更新(先删除后插入)
				int delFlag=-1;
				try {
					resultRegionId=smsAreaMapper.qryRegionId(mgrId);
					delFlag=smsAreaMapper.delSmsBaseStation(mgrId);
				} catch (Exception e) {
					e.printStackTrace();
					throw new SmsException("插入基站信息异常");
				}
				ConcurrentLinkedQueue<SmsBaseStation> SmsBaseStationList = new ConcurrentLinkedQueue<SmsBaseStation>();
				stationNum=list.size();
				System.out.println("stationNum==county==================="+stationNum);
				if(list.size()>0&&resultRegionId!=""){
					for (int i = 0; i < list.size(); i++) {
						SmsBaseStation baseStation = new SmsBaseStation();
						baseStation.setCityId(cityId);
						baseStation.setId(mgrId);
						baseStation.setRegionId(resultRegionId);
						baseStation.setStationId(list.get(i).getStationMarkId());
						baseStation.setStationName(list.get(i).getStationMarkName());
						SmsBaseStationList.add(baseStation);
					}
				}
				if(delFlag>0){//删除成功再插入
					saveFlag=this.insertSmsBaseStation(mgrId, SmsBaseStationList);
				}
			}else{//不存在就添加
				resultRegionId= this.getRegionId();
				ConcurrentLinkedQueue<SmsBaseStation> SmsBaseStationList = new ConcurrentLinkedQueue<SmsBaseStation>();
				stationNum=list.size();
				if(list.size()>0&&resultRegionId!=""){
					for (int i = 0; i < list.size(); i++) {
						SmsBaseStation baseStation = new SmsBaseStation();
						baseStation.setCityId(cityId);
						baseStation.setId(mgrId);
						baseStation.setRegionId(resultRegionId);
						baseStation.setStationId(list.get(i).getStationMarkId());
						baseStation.setStationName(list.get(i).getStationMarkName());
						SmsBaseStationList.add(baseStation);
					}
				}
				saveFlag=this.insertSmsBaseStation(mgrId, SmsBaseStationList);
			}
		}else{
			saveFlag=-99;
		}

		result.add(saveFlag);//是否保存成功
		result.add(stationNum);//保存的基站数
		result.add(resultRegionId);//区域ID
		result.add("1");//区域类型 1表示行政区域组合
		result.add(countyId);// 行政区域字符串
		return result;
	}
	@SystemServiceLog(description = "查询选择行政范围内所有基站信息", value = false)
	public List<SmsAllStation> findAllStationIdsByCounty(String stationIds) {
		List<SmsAllStation> list = new ArrayList<SmsAllStation>();
		SmsAllStation smsAllStation = null;
		List<String> result = Arrays.asList(stationIds.split(","));
		for(int i=0;i<result.size();i++ ){
			smsAllStation = new SmsAllStation();
			smsAllStation.setStationMarkId(result.get(i));
			list.add(smsAllStation);
		}
		return list;
	}
	public Integer findHeatMapLevel() {
		int limit = 0;
		try {
			limit = smsAreaMapper.findHeatMapLevel();
		} catch (Exception e) {
			e.printStackTrace();
			log.error("查询热力图显示极限等级");
			throw new SmsException("查询热力图显示极限等级出现异常");
		}
		return limit;
	}
//	@SystemServiceLog(description = "插入气象局圈划发送范围表", value = false)
	public int qxjScopeSave(String scopeId,String cityId,String scopeType, String longAndLats) {
		int result=-1;
		 try {
				result = smsAreaMapper.qxjScopeSave(scopeId,cityId, scopeType, longAndLats);
			} catch (Exception e) {
				e.printStackTrace();
				log.error("插入气象局圈划发送范围表");
				throw new SmsException("插入气象局圈划发送范围表出现异常");
			}		 
			 return result;
	}
	
//	@SystemServiceLog(description = "气象局圈划发送范围表查询", value = false)
	public QxjSendScope qxjScopeQry(String scopeId) {
		 //if(longAndLats!=null&&!"".equals(longAndLats)){
			  //longAndLats = longAndLats.replace('+', '|');
		  //}
		QxjSendScope qxjSendScope=null;
		 try {
			 	qxjSendScope = smsAreaMapper.qxjScopeQry(scopeId);
//				commonService.createSmsOperLog("2", "插入气象局圈划发送范围表"+scopeId, "0", "气象局发送范围");
			} catch (Exception e) {
				e.printStackTrace();
				log.error("插入气象局圈划发送范围表");
//				commonService.createSmsOperLog("2", "插入气象局圈划发送范围表"+scopeId, "1", "气象局发送范围");
				throw new SmsException("插入气象局圈划发送范围表出现异常");
			}
		return qxjSendScope;
	}
	@SystemServiceLog(description = "查询盱眙基站经纬度" , value = false)
	public List<XuYiStation> findXuYiStations(){
		return smsAreaMapper.findXuYiStations();
	}
	
	@SystemServiceLog(description = "查询盱眙供电站经纬度" , value = false)
	public List<List<List<XuYiStation>>> findXuYiSubStations(String pathName,String subStationName){
		String subPathName="";
		List<String> subPathNames = null;
		List<String> subStationNames =null;
		List<List<XuYiStation>> xuYiSUbStationLists = new ArrayList<List<XuYiStation>>();
		List<List<List<XuYiStation>>> totalSubList=new ArrayList<List<List<XuYiStation>>>();
		
		if("all".equals(pathName)){
			 subPathNames= smsAreaMapper.findXuYiSubPathNames();
		}else{
			subPathNames= new ArrayList<String>();
			subPathNames.add(pathName);
		}

		if(null!=subPathNames &&!subPathNames.isEmpty()){
			for(int i = 0; i<subPathNames.size(); i++){
				subPathName=subPathNames.get(i);
				//totalSubList.set(i, subPathName);
				if("all".equals(subStationName)){
					subStationNames = smsAreaMapper.findXuYiSubStationNames(subPathName);
				}else{
					subStationNames= new ArrayList<String>();
					subStationNames.add(subStationName);
				}
				 
				if (subStationNames!=null && !subStationNames.isEmpty() ) {
					for (String subStationName1 : subStationNames) {
						System.out.println("----"+subStationName1);
						List<XuYiStation> XuYiSubStations = smsAreaMapper.findXuYiSubStations("",subStationName1,"");
						//List<XuYiStation> sort = sort(XuYiSubStations);
						xuYiSUbStationLists.add(XuYiSubStations);
						
					}
				}
				totalSubList.add(xuYiSUbStationLists);
				xuYiSUbStationLists = new ArrayList<List<XuYiStation>>();
			}
		}
		//System.out.println(totalSubList.toString());
		return totalSubList;
	}
	/**
	 * 查询盱眙供电站列表展示
	 * @param pathName
	 * @param subStationName
	 * @return
	 */
	@SystemServiceLog(description = "查询盱眙供电站列表" , value = false)
	public PageInfo<XuYiStation> findXuYiSubStations2(int page, int limit,String pathName,String subStationName,String subSeq){
		
		PageHelper.startPage(page, limit);
		String subPathName="";
		List<String> subPathNames = new ArrayList<String>();
		List<String> subStationNames =new ArrayList<String>();
		List<XuYiStation> xuYiSUbStationLists = new ArrayList<XuYiStation>();
		
		if(("all".equals(pathName) || null == pathName)&&"".equals(subStationName)){
			xuYiSUbStationLists = smsAreaMapper.findXuYiSubStations("","",subSeq);
		}else{
			if("all".equals(pathName)){
				pathName="";
			}
			subPathNames= new ArrayList<String>();
			subPathNames.add(pathName);
			for(int i = 0; i<subPathNames.size(); i++){
				subPathName=subPathNames.get(i);
				//totalSubList.set(i, subPathName);
				if("all".equals(subStationName) || null == subStationName){
					//subStationNames = smsAreaMapper.findXuYiSubStationNames(subPathName);
					xuYiSUbStationLists = smsAreaMapper.findXuYiSubStations(subPathName,"",subSeq);
				}else{
					subStationNames= new ArrayList<String>();
					subStationNames.add(subStationName);
					for (String subStationName1 : subStationNames) { 
						List<XuYiStation> XuYiSubStations = smsAreaMapper.findXuYiSubStations(subPathName,subStationName1,subSeq);
						//List<XuYiStation> sort = sort(XuYiSubStations);
						for(XuYiStation xuYiStation : XuYiSubStations){
							xuYiSUbStationLists.add(xuYiStation);
						}
					}
				}
			}
		}
		PageInfo<XuYiStation> pageInfo = new PageInfo<XuYiStation>(xuYiSUbStationLists);
		return pageInfo;
	}
	
	
	/**
	 * 查询盱眙供电站列表展示
	 * @param pathName
	 * @param subStationName
	 * @return
	 */
	@SystemServiceLog(description = "查询盱眙供电站列表" , value = false)
	public PageInfo<XuYiStation> findXuYiSubStations3(int page, int limit,String pathName,String subStationName){
		
		PageHelper.startPage(page, limit);
		List<XuYiStation> xuYiSUbStationLists = new ArrayList<XuYiStation>();
		if("all".equals(pathName)){
			pathName = "";
		}
		if("all".equals(subStationName)){
			subStationName = "";
		}
		
		xuYiSUbStationLists = smsAreaMapper.findXuYiSubStations3(pathName,subStationName);
		
		PageInfo<XuYiStation> pageInfo = new PageInfo<XuYiStation>(xuYiSUbStationLists);
		return pageInfo;
	}
	
	
	
	private List<XuYiStation> sort(List<XuYiStation> XuYiSubStations){
		HashMap<Double, XuYiStation> map = new HashMap<Double, XuYiStation>();
		for (XuYiStation xuYiStation : XuYiSubStations) {
			double key = Double.parseDouble(xuYiStation.getLng()) * Double.parseDouble(xuYiStation.getLng()) + Double.parseDouble(xuYiStation.getLat()) *Double.parseDouble(xuYiStation.getLat());
			map.put(key, xuYiStation);
		}
		Set<Double> entrySet = map.keySet();
		List<Double> list = new ArrayList<Double>(entrySet);
		Collections.sort(list);
		XuYiStation xuYiStation = map.get(list.get(0));
		HashMap<Double,XuYiStation> slope = getSlope(XuYiSubStations, xuYiStation);
		List<XuYiStation> sort = new ArrayList<XuYiStation>();
		sort.add(xuYiStation);
		Set<Double> slopeSet = slope.keySet();
		List<Double> slopeList = new ArrayList<Double>(slopeSet);
		Collections.sort(slopeList);
		for (Double double1 : slopeList) {
			sort.add(slope.get(double1));
		}
		return sort;
	}
	private HashMap<Double, XuYiStation> getSlope(List<XuYiStation> xuYiSubStations,XuYiStation xuYiStation){
		xuYiSubStations.remove(xuYiStation);
		HashMap<Double, XuYiStation> result = new HashMap<Double, XuYiStation>();
		for (XuYiStation xuYiStationOther : xuYiSubStations) {
			double lat = Double.parseDouble(xuYiStation.getLat())- Double.parseDouble(xuYiStationOther.getLat());
			double lng = Double.parseDouble(xuYiStation.getLng()) -  Double.parseDouble(xuYiStationOther.getLng());
			double slope = lat/lng;
			result.put(slope, xuYiStationOther);
		}
		return result;
	}
	@SystemServiceLog(description = "查询盱眙供电站经纬度" , value = false)
	public List<String> findPathName(){
		List<String> pathNameList = new ArrayList<String>();
		pathNameList= smsAreaMapper.findXuYiSubPathNames();
		return pathNameList;
	}

	public List<String> findRegionName(String pathName) {
		List<String> regionNameList = new ArrayList<String>();
		regionNameList= smsAreaMapper.findXuYiSubStationNames(pathName);
		return regionNameList;
	}
	
	public List<String> findRegionNameLike(String pathName,String regionName) {
		List<String> regionNameList = new ArrayList<String>();
		System.out.println(regionName);
		regionNameList= smsAreaMapper.findXuYiSubStationNameLike(pathName,regionName);
		return regionNameList;
	}
	
	
	public PageInfo<XuYiStation> findRegionNameLike2(int page, int limit,String regionName,String alreadyRelate) {
		List<XuYiStation> regionNameList = new ArrayList<XuYiStation>();
		PageHelper.startPage(page, limit);
		String[] alreadyRelateList = null;
		List<String> alreadyRelateList2 = null;
		System.out.println("----"+alreadyRelate);
		if(""!=alreadyRelate&&null!=alreadyRelate){
			alreadyRelateList = alreadyRelate.split(",");
			alreadyRelateList2 = new ArrayList<String>();
			for(String region:alreadyRelateList){
				alreadyRelateList2.add(region);
			}
		}
		
		regionNameList= smsAreaMapper.findXuYiSubStationNameLike2(regionName,alreadyRelateList2);
		PageInfo<XuYiStation> pageInfo = new PageInfo<XuYiStation>(regionNameList);
		return pageInfo;
	}
	
	public List<XuYiStation> BdToGPS(String gps) throws UnsupportedEncodingException{
		//log.info("---"+gps);
		String url = "http://api.map.baidu.com/ag/coord/convert";
		Map<String, String> querys = new HashMap<String, String>();
		List<XuYiStation> baiduList= new ArrayList<XuYiStation>();
		//XuYiStation xuYiStation = new XuYiStation();
		String lng = "";
		String lat = "";
		String name = "";
		String[] gpsList;
		if(null!=gps && ""!=gps){
			gpsList = gps.split(",");
		
		String[] lnglat ;
		for(String gpsString : gpsList){
			XuYiStation xuYiStation = new XuYiStation();
			if(null!=gpsString && ""!=gpsString ){
				//log.info("gpsString----"+gpsString);
				lnglat=gpsString.split("\\|");
				if(null!=lnglat && lnglat.length!=0){
					lng=lnglat[0];
					lat=lnglat[1];
					name=lnglat[2];
					//log.info(lng+"---"+lat+"---"+name);
				}
			}
			querys.put("from", "0");
			querys.put("to", "4");
			querys.put("x", lng);
			querys.put("y", lat);
			BaseResult<String> sendGet = HttpClientUtil.sendGet(url, querys, "utf-8", null);
			if ("0".equals(sendGet.getRetCode())) {
				BdResult data =  JSONObject.parseObject(sendGet.getData(), BdResult.class) ;
				if ("0".equals(data.getError())) {
					String x = new String(Base64Utils.decode(data.getX().getBytes()), "utf-8");
					String y = new String(Base64Utils.decode(data.getY().getBytes()), "utf-8");
					xuYiStation.setLng(x);
					xuYiStation.setLat(y);
					xuYiStation.setName(name);
					baiduList.add(xuYiStation);
				}
			}
		}
		}
		return baiduList;
		
	}


	
}




